﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SAKS.IServices;
using NHibernate;
namespace SAKS.Controllers
{
    public class DownloadController : ControllerBase
    {
        public IDocumentServices DocumentServices { get; set; }

        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            DocumentServices.Session = GetCurrentSession(requestContext);
        }

        public ActionResult Document(Guid? id)
        {
            if (id != null)
            {
                var file = DocumentServices.GetFile((Guid)id);
                if (file != null)
                {
                    return File(file.Doc, file.Type, file.Name);
                }
            }
            return HttpNotFound();       
        }

    }
}
